package gw.com.android.ui.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import www.com.library.util.DeviceUtil;

/**
 * @author jett
 * @since 2017-12-08.
 */
public class RedView extends View {

    private int mWidth;
    private int mHeight;
    private int mRadiu;

    private int strokeWidth;

    private Paint mPaint = new Paint();
    private Paint edgePaint = new Paint();

    public RedView(Context context) {
        super(context);
        init();
    }

    public RedView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public RedView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        strokeWidth = DeviceUtil.instance().dip2px(2, getContext());

        mPaint.setColor(Color.RED);

        edgePaint.setStyle(Paint.Style.STROKE);
        edgePaint.setStrokeWidth(strokeWidth);
        edgePaint.setColor(Color.WHITE);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        mWidth = this.getMeasuredWidth();
        mHeight = this.getMeasuredHeight();
        mRadiu = Math.min(mWidth, mHeight) / 2;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(mWidth / 2, mHeight / 2, mRadiu - strokeWidth, mPaint);
        canvas.drawCircle(mWidth / 2, mHeight / 2, mRadiu - strokeWidth, edgePaint);
    }

}